package com.RMP
{
    import flash.display.*;
    import flash.events.*;

    public class ProjectIconShell extends Sprite
    {
        var startIndexChar:String;
        var myXMLList:XMLList;
        var counter:int;
        var imagePath:String;
        var fadeSpeed:Number;
        var iconsArray:Array;
        var imageBorder:String;
        var iconImage:ProjectIconImage;
        var myRoot:MovieClip;
        var startIndexNum:int;

        public function ProjectIconShell(param1:MovieClip, param2:Number, param3:XMLList, param4) : void
        {
            trace("ICON SHELL");
            myRoot = param1;
            fadeSpeed = param2;
            myXMLList = param3;
            startIndexNum = param4;
            buildList();
            myRoot.stage.addEventListener(Event.RESIZE, onResizer);
            doResize();
            return;
        }

        function doResize() : void
        {
            var _loc_1:int = 0;
            _loc_1 = 0;
            while (_loc_1 < counter)
            {
                
                iconsArray[_loc_1].x = Math.round(_loc_1 % 4 * 3 * (myRoot.unitW + myRoot.gutterW));
                iconsArray[_loc_1].y = Math.round(2 + Math.floor(_loc_1 / 4) * 2 * (myRoot.unitH + myRoot.gutterH));
                _loc_1++;
            }
            return;
        }

        function buildList() : void
        {
            var startPoint:*;
            var i:int;
            var myLabel:String;
            startPoint = (startIndexNum - 1) * 8;
            counter = 0;
            iconsArray = new Array();
            i = startPoint;
            while (i < myXMLList.item.length())
            {
                
                switch(myRoot.pathNames[1])
                {
                    case "architecture":
                    {
                        var _loc_3:int = 0;
                        var _loc_4:* = myRoot.myXML.nav.projects.tier0[0].tier1[2].tier2.item;
                        var _loc_2:* = new XMLList("");
                        for each (_loc_5 in _loc_4)
                        {
                            
                            var _loc_6:* = _loc_4[_loc_3];
                            with (_loc_4[_loc_3])
                            {
                                if (@id == myXMLList.item[i].@id)
                                {
                                    _loc_2[_loc_3] = _loc_5;
                                }
                            }
                        }
                        imagePath = _loc_2.thumbnails.@icon;
                        var _loc_3:int = 0;
                        var _loc_4:* = myRoot.myXML.nav.projects.tier0[0].tier1[2].tier2.item;
                        var _loc_2:* = new XMLList("");
                        for each (_loc_5 in _loc_4)
                        {
                            
                            var _loc_6:* = _loc_4[_loc_3];
                            with (_loc_4[_loc_3])
                            {
                                if (@id == myXMLList.item[i].@id)
                                {
                                    _loc_2[_loc_3] = _loc_5;
                                }
                            }
                        }
                        imageBorder = _loc_2.thumbnails.@iBorder;
                        trace("imagePath " + imagePath);
                        break;
                    }
                    case "products":
                    {
                        var _loc_3:int = 0;
                        var _loc_4:* = myRoot.myXML.nav.projects.tier0[1].tier1[0].tier2.item;
                        var _loc_2:* = new XMLList("");
                        for each (_loc_5 in _loc_4)
                        {
                            
                            var _loc_6:* = _loc_4[_loc_3];
                            with (_loc_4[_loc_3])
                            {
                                if (@id == myXMLList.item[i].@id)
                                {
                                    _loc_2[_loc_3] = _loc_5;
                                }
                            }
                        }
                        imagePath = _loc_2.thumbnails.@icon;
                        var _loc_3:int = 0;
                        var _loc_4:* = myRoot.myXML.nav.projects.tier0[1].tier1[0].tier2.item;
                        var _loc_2:* = new XMLList("");
                        for each (_loc_5 in _loc_4)
                        {
                            
                            var _loc_6:* = _loc_4[_loc_3];
                            with (_loc_4[_loc_3])
                            {
                                if (@id == myXMLList.item[i].@id)
                                {
                                    _loc_2[_loc_3] = _loc_5;
                                }
                            }
                        }
                        imageBorder = _loc_2.thumbnails.@iBorder;
                        break;
                    }
                    case "exhibitions":
                    {
                        var _loc_3:int = 0;
                        var _loc_4:* = myRoot.myXML.nav.projects.tier0[2].tier1[0].tier2.item;
                        var _loc_2:* = new XMLList("");
                        for each (_loc_5 in _loc_4)
                        {
                            
                            var _loc_6:* = _loc_4[_loc_3];
                            with (_loc_4[_loc_3])
                            {
                                if (@id == myXMLList.item[i].@id)
                                {
                                    _loc_2[_loc_3] = _loc_5;
                                }
                            }
                        }
                        imagePath = _loc_2.thumbnails.@icon;
                        var _loc_3:int = 0;
                        var _loc_4:* = myRoot.myXML.nav.projects.tier0[2].tier1[0].tier2.item;
                        var _loc_2:* = new XMLList("");
                        for each (_loc_5 in _loc_4)
                        {
                            
                            var _loc_6:* = _loc_4[_loc_3];
                            with (_loc_4[_loc_3])
                            {
                                if (@id == myXMLList.item[i].@id)
                                {
                                    _loc_2[_loc_3] = _loc_5;
                                }
                            }
                        }
                        imageBorder = _loc_2.thumbnails.@iBorder;
                        break;
                    }
                    case "press":
                    {
                        imagePath = myXMLList.item[i].media.@thumb;
                        imageBorder = myXMLList.item[i].media.@tBorder;
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                myLabel = myXMLList.item[i].@label;
                iconImage = new ProjectIconImage(myRoot, fadeSpeed, myLabel, counter, myXMLList.item[i].@id, imagePath, imageBorder);
                addChild(iconImage);
                iconImage.buttonMode = true;
                iconImage.mouseChildren = false;
                iconImage.addEventListener(MouseEvent.ROLL_OVER, btnRollOver);
                iconImage.addEventListener(MouseEvent.ROLL_OUT, btnRollOut);
                iconImage.addEventListener(MouseEvent.CLICK, btnClick);
                iconsArray.push(iconImage);
                var _loc_3:* = counter + 1;
                counter = _loc_3;
                if (counter == 8)
                {
                    break;
                }
                i = (i + 1);
            }
            return;
        }

        function onResizer(event:Event)
        {
            doResize();
            return;
        }

        function btnRollOver(event:MouseEvent)
        {
            trace("over");
            event.currentTarget.rollOverEvent();
            myRoot.changeToolTipText(event.currentTarget.myText);
            myRoot.showToolTipNoDelay();
            return;
        }

        function btnRollOut(event:MouseEvent)
        {
            trace("out");
            myRoot.closeToolTipWithDelay();
            event.currentTarget.rollOutEvent();
            return;
        }

        function btnClick(event:MouseEvent) : void
        {
            myRoot.closeToolTip();
            updateAddress(event.currentTarget.dbId);
            return;
        }

        function updateAddress(param1) : void
        {
            var incomingId:* = param1;
            switch(myRoot.pathNames[1])
            {
                case "architecture":
                {
                    switch(myRoot.pathNames[2])
                    {
                        case "type":
                        {
                            var _loc_4:int = 0;
                            var _loc_7:int = 0;
                            var _loc_10:int = 0;
                            var _loc_11:* = myRoot.myXML.nav.projects.tier0;
                            var _loc_9:* = new XMLList("");
                            for each (_loc_12 in _loc_11)
                            {
                                
                                var _loc_13:* = _loc_11[_loc_10];
                                with (_loc_11[_loc_10])
                                {
                                    if (@label == "Architecture")
                                    {
                                        _loc_9[_loc_10] = _loc_12;
                                    }
                                }
                            }
                            var _loc_8:* = _loc_9.tier1;
                            var _loc_6:* = new XMLList("");
                            for each (_loc_9 in _loc_8)
                            {
                                
                                var _loc_10:* = _loc_8[_loc_7];
                                with (_loc_8[_loc_7])
                                {
                                    if (@label == "Name")
                                    {
                                        _loc_6[_loc_7] = _loc_9;
                                    }
                                }
                            }
                            var _loc_5:* = _loc_6.tier2.item;
                            var _loc_3:* = new XMLList("");
                            for each (_loc_6 in _loc_5)
                            {
                                
                                var _loc_7:* = _loc_5[_loc_4];
                                with (_loc_5[_loc_4])
                                {
                                    if (@id == incomingId)
                                    {
                                        _loc_3[_loc_4] = _loc_6;
                                    }
                                }
                            }
                            if (_loc_3.@sub == "T")
                            {
                                myRoot.clickPathNames = ["projects", "architecture", "type", "icons", myRoot.pathNames[4], incomingId, "sub", 0, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "architecture" + "/" + "type" + "/" + "icons" + "/" + myRoot.pathNames[4] + "/" + incomingId + "/" + "sub" + "/" + 0 + "/" + 0 + "/");
                            }
                            else
                            {
                                myRoot.clickPathNames = ["projects", "architecture", "type", "icons", myRoot.pathNames[4], incomingId, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "architecture" + "/" + "type" + "/" + "icons" + "/" + myRoot.pathNames[4] + "/" + incomingId + "/" + 0 + "/");
                            }
                            break;
                        }
                        case "visual":
                        {
                            var _loc_4:int = 0;
                            var _loc_7:int = 0;
                            var _loc_10:int = 0;
                            var _loc_11:* = myRoot.myXML.nav.projects.tier0;
                            var _loc_9:* = new XMLList("");
                            for each (_loc_12 in _loc_11)
                            {
                                
                                var _loc_13:* = _loc_11[_loc_10];
                                with (_loc_11[_loc_10])
                                {
                                    if (@label == "Architecture")
                                    {
                                        _loc_9[_loc_10] = _loc_12;
                                    }
                                }
                            }
                            var _loc_8:* = _loc_9.tier1;
                            var _loc_6:* = new XMLList("");
                            for each (_loc_9 in _loc_8)
                            {
                                
                                var _loc_10:* = _loc_8[_loc_7];
                                with (_loc_8[_loc_7])
                                {
                                    if (@label == "Name")
                                    {
                                        _loc_6[_loc_7] = _loc_9;
                                    }
                                }
                            }
                            var _loc_5:* = _loc_6.tier2.item;
                            var _loc_3:* = new XMLList("");
                            for each (_loc_6 in _loc_5)
                            {
                                
                                var _loc_7:* = _loc_5[_loc_4];
                                with (_loc_5[_loc_4])
                                {
                                    if (@id == incomingId)
                                    {
                                        _loc_3[_loc_4] = _loc_6;
                                    }
                                }
                            }
                            if (_loc_3.@sub == "T")
                            {
                                myRoot.clickPathNames = ["projects", "architecture", "visual", myRoot.pathNames[3], incomingId, "sub", 0, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "architecture" + "/" + "visual" + "/" + myRoot.pathNames[3] + "/" + incomingId + "/" + "sub" + "/" + 0 + "/" + 0 + "/");
                            }
                            else
                            {
                                myRoot.clickPathNames = ["projects", "architecture", "visual", myRoot.pathNames[3], incomingId, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "architecture" + "/" + "visual" + "/" + myRoot.pathNames[3] + "/" + incomingId + "/" + 0 + "/");
                            }
                            break;
                        }
                        case "icons":
                        {
                            var _loc_4:int = 0;
                            var _loc_7:int = 0;
                            var _loc_10:int = 0;
                            var _loc_11:* = myRoot.myXML.nav.projects.tier0;
                            var _loc_9:* = new XMLList("");
                            for each (_loc_12 in _loc_11)
                            {
                                
                                var _loc_13:* = _loc_11[_loc_10];
                                with (_loc_11[_loc_10])
                                {
                                    if (@label == "Architecture")
                                    {
                                        _loc_9[_loc_10] = _loc_12;
                                    }
                                }
                            }
                            var _loc_8:* = _loc_9.tier1;
                            var _loc_6:* = new XMLList("");
                            for each (_loc_9 in _loc_8)
                            {
                                
                                var _loc_10:* = _loc_8[_loc_7];
                                with (_loc_8[_loc_7])
                                {
                                    if (@label == "Name")
                                    {
                                        _loc_6[_loc_7] = _loc_9;
                                    }
                                }
                            }
                            var _loc_5:* = _loc_6.tier2.item;
                            var _loc_3:* = new XMLList("");
                            for each (_loc_6 in _loc_5)
                            {
                                
                                var _loc_7:* = _loc_5[_loc_4];
                                with (_loc_5[_loc_4])
                                {
                                    if (@id == incomingId)
                                    {
                                        _loc_3[_loc_4] = _loc_6;
                                    }
                                }
                            }
                            if (_loc_3.@sub == "T")
                            {
                                myRoot.clickPathNames = ["projects", "architecture", "icons", myRoot.pathNames[3], incomingId, "sub", 0, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "architecture" + "/" + "icons" + "/" + myRoot.pathNames[3] + "/" + incomingId + "/" + "sub" + "/" + 0 + "/" + 0 + "/");
                            }
                            else
                            {
                                myRoot.clickPathNames = ["projects", "architecture", "icons", myRoot.pathNames[3], incomingId, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "architecture" + "/" + "icons" + "/" + myRoot.pathNames[3] + "/" + incomingId + "/" + 0 + "/");
                            }
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    break;
                }
                case "products":
                {
                    switch(myRoot.pathNames[2])
                    {
                        case "visual":
                        {
                            var _loc_4:int = 0;
                            var _loc_7:int = 0;
                            var _loc_10:int = 0;
                            var _loc_11:* = myRoot.myXML.nav.projects.tier0;
                            var _loc_9:* = new XMLList("");
                            for each (_loc_12 in _loc_11)
                            {
                                
                                var _loc_13:* = _loc_11[_loc_10];
                                with (_loc_11[_loc_10])
                                {
                                    if (@label == "Products")
                                    {
                                        _loc_9[_loc_10] = _loc_12;
                                    }
                                }
                            }
                            var _loc_8:* = _loc_9.tier1;
                            var _loc_6:* = new XMLList("");
                            for each (_loc_9 in _loc_8)
                            {
                                
                                var _loc_10:* = _loc_8[_loc_7];
                                with (_loc_8[_loc_7])
                                {
                                    if (@label == "Name")
                                    {
                                        _loc_6[_loc_7] = _loc_9;
                                    }
                                }
                            }
                            var _loc_5:* = _loc_6.tier2.item;
                            var _loc_3:* = new XMLList("");
                            for each (_loc_6 in _loc_5)
                            {
                                
                                var _loc_7:* = _loc_5[_loc_4];
                                with (_loc_5[_loc_4])
                                {
                                    if (@id == incomingId)
                                    {
                                        _loc_3[_loc_4] = _loc_6;
                                    }
                                }
                            }
                            if (_loc_3.@sub == "T")
                            {
                                myRoot.clickPathNames = ["projects", "products", "visual", myRoot.pathNames[3], incomingId, "sub", 0, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "products" + "/" + "visual" + "/" + myRoot.pathNames[3] + "/" + incomingId + "/" + "sub" + "/" + 0 + "/" + 0 + "/");
                            }
                            else
                            {
                                myRoot.clickPathNames = ["projects", "products", "visual", myRoot.pathNames[3], incomingId, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "products" + "/" + "visual" + "/" + myRoot.pathNames[3] + "/" + incomingId + "/" + 0 + "/");
                            }
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    break;
                }
                case "exhibitions":
                {
                    switch(myRoot.pathNames[2])
                    {
                        case "visual":
                        {
                            var _loc_4:int = 0;
                            var _loc_7:int = 0;
                            var _loc_10:int = 0;
                            var _loc_11:* = myRoot.myXML.nav.projects.tier0;
                            var _loc_9:* = new XMLList("");
                            for each (_loc_12 in _loc_11)
                            {
                                
                                var _loc_13:* = _loc_11[_loc_10];
                                with (_loc_11[_loc_10])
                                {
                                    if (@label == "Exhibitions")
                                    {
                                        _loc_9[_loc_10] = _loc_12;
                                    }
                                }
                            }
                            var _loc_8:* = _loc_9.tier1;
                            var _loc_6:* = new XMLList("");
                            for each (_loc_9 in _loc_8)
                            {
                                
                                var _loc_10:* = _loc_8[_loc_7];
                                with (_loc_8[_loc_7])
                                {
                                    if (@label == "Name")
                                    {
                                        _loc_6[_loc_7] = _loc_9;
                                    }
                                }
                            }
                            var _loc_5:* = _loc_6.tier2.item;
                            var _loc_3:* = new XMLList("");
                            for each (_loc_6 in _loc_5)
                            {
                                
                                var _loc_7:* = _loc_5[_loc_4];
                                with (_loc_5[_loc_4])
                                {
                                    if (@id == incomingId)
                                    {
                                        _loc_3[_loc_4] = _loc_6;
                                    }
                                }
                            }
                            if (_loc_3.@sub == "T")
                            {
                                myRoot.clickPathNames = ["projects", "exhibitions", "visual", myRoot.pathNames[3], incomingId, "sub", 0, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "exhibitions" + "/" + "visual" + "/" + myRoot.pathNames[3] + "/" + incomingId + "/" + "sub" + "/" + 0 + "/" + 0 + "/");
                            }
                            else
                            {
                                myRoot.clickPathNames = ["projects", "exhibitions", "visual", myRoot.pathNames[3], incomingId, 0];
                                myRoot.updateAddress("/" + "projects" + "/" + "exhibitions" + "/" + "visual" + "/" + myRoot.pathNames[3] + "/" + incomingId + "/" + 0 + "/");
                            }
                            break;
                        }
                        default:
                        {
                            break;
                        }
                    }
                    break;
                }
                case "press":
                {
                    myRoot.clickPathNames = ["practice", "press", "video", myRoot.pathNames[3], incomingId];
                    myRoot.updateAddress("/" + "practice" + "/" + "press" + "/" + "video" + "/" + myRoot.pathNames[3] + "/" + incomingId + "/");
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }

    }
}
